*------------------------------------------------------------------------------*
						*** TABLE S5. ATTENUATION BIAS ***
*------------------------------------------------------------------------------*

***PROGRAM FOR LAGGED PM10 ON CURRENT PM10
cap program drop reg_tab_PM10lags
program define reg_tab_PM10lags, sclass
	args cmd spec 
	/* ARGUMENTS
	cmd: command (reg or areg)
	spec: number of the specification 
	*/

	// THE FOLLOWING LOOP RUNS THE ANALYSIS SEPARATELY FOR ALL DEPENDENT VARIABLES
	local Y : word count $depvars_tab_PM10lags // PICKS EACH VARIABLE ONE BY ONE FROM MACRO
	forvalues i=1/`Y' {
		local y : word `i' of $depvars_tab_PM10lags
		`cmd' `y' ${spec`spec'} // THIS RUNS THE REGRESSION
		estadd ysumm
		
		// THIS SAVES THE COEFFICIENT VECTOR
		mat b = e(b) 
		scalar bPM10_`spec'_`i'	= b[1,1] // PM10 coefficient
		
		mat V = e(V) // THIS SAVES THE VARIANCE MATRIX
		
		// THE FOLLOWING SAVES STANDARD ERRORS, R2, N AND MEAN DEP. VAR. AS SCALARS
		scalar sePM10_`spec'_`i' = sqrt(V[1,1]) // PM10 SE
		scalar r2_`spec'_`i' 	 = e(r2) // r-squared
		scalar N_`spec'_`i'  	 = e(N) // N
		scalar YM_`spec'_`i' 	 = e(ymean)  // Mean Dep. Var.
				
		// THE FOLLOWING PRODUCES SIGNIFICANCE STARS AND SAVES THEM AS LOCALS
		scalar pPM10_`spec'_`i' = 2*(1-normal(abs(bPM10_`spec'_`i' / sePM10_`spec'_`i')))
		local starPM10_`spec'_`i' ""
		if pPM10_`spec'_`i' < .1 {	
			local starPM10_`spec'_`i' *
		}
		if pPM10_`spec'_`i' < .05 {
			local starPM10_`spec'_`i' **
		}
		if pPM10_`spec'_`i' < .01 {
			local starPM10_`spec'_`i' ***
		}
		global starPM10_`spec'_`i' = "`starPM10_`spec'_`i''"
		
	} //i
end

*------------------------------------------------------------------------------*

***Macros
global depvars_tab_PM10lags "lag_PM10_10ug_5_30km lag_PM10_10ug_10_30km lag_PM10_10ug_15_30km lag_PM10_10ug_20_30km lag_PM10_10ug_25_30km lag_PM10_10ug_30_30km"


**Specifications with FEs only
global spec1 " PM10_30km_10ug , ${hdfe_opt}, if samplePM10_allcontrols == 1"


*------------------------------------------------------------------------------*

use "${tempdata}kreise_complete_all.dta", clear

*------------------------------------------------------------------------------*

***Regressions
*With FEs
reg_tab_PM10lags reghdfe 1

*------------------------------------------------------------------------------*

***Table without FEs
gen str table=""

// FIRST PANEL. MODEL OUTCOMES 
local i=1
local line "PM10 ($10\mu g / m^3$)&"
local line "`line'" $f_b bPM10_1_1 "\sym{$starPM10_1_1}" "&" $f_b bPM10_1_2 "\sym{$starPM10_1_2}" "&" $f_b bPM10_1_3 "\sym{$starPM10_1_3}" "&" $f_b bPM10_1_4 "\sym{$starPM10_1_4}" "&" $f_b bPM10_1_5 "\sym{$starPM10_1_5}" "&" $f_b bPM10_1_6 "\sym{$starPM10_1_6}" " \\ "
local line: display "`line'" 
qui replace table="`line'" in `i'
// PM10 s.e.
local i=`i'+1
local line "&" "(" $f_se sePM10_1_1 ")" "&" "(" $f_se sePM10_1_2 ")" "&" "(" $f_se sePM10_1_3 ")" "&" "(" $f_se sePM10_1_4 ")" "&" "(" $f_se sePM10_1_5 ")" "&" "(" $f_se sePM10_1_6 ")" " \\ " 
local line: display "`line'" 
qui replace table="`line'" in `i'
// Y mean
local i=`i'+1
local line "Mean dep. var.&"
local line "`line'" $f_YM YM_1_1 "&" $f_YM YM_1_2 "&" $f_YM YM_1_3 "&" $f_YM YM_1_4 "&" $f_YM YM_1_5 "&" $f_YM YM_1_6 " \\ "
local line: display "`line'" 
qui replace table="`line'" in `i'
// R2
local i=`i'+1
local line "R$^2$ & "
local line "`line'" $f_r2 r2_1_1 "&" $f_r2 r2_1_2 "&" $f_r2 r2_1_3 "&" $f_r2 r2_1_4 "&" $f_r2 r2_1_5 "&" $f_r2 r2_1_6 " \\ " 
local line: display "`line'" 
qui replace table="`line'" in `i'
// Observations
local i=`i'+1
local line "N&"
local line "`line'" $f_N N_1_1 "&" $f_N N_1_2 "&" $f_N N_1_3 "&" $f_N N_1_4 "&" $f_N N_1_5 "&" $f_N N_1_6 " \\ "
local line: display "`line'" 
qui replace table="`line'" in `i'

// CONTROLS
local i=`i'+1
qui replace table="\multicolumn{7}{l}{\textit{Controls} } \\ " in `i'
local i=`i'+1
qui replace table="\ \ County FE & \checkmark & \checkmark & \checkmark & \checkmark & \checkmark & \checkmark \\" in `i'
local i=`i'+1
qui replace table="\ \ El. Date FE & \checkmark & \checkmark & \checkmark & \checkmark & \checkmark & \checkmark %\\" in `i'
local i=`i'+1


**Output to .tex file
outfile table using "${outputs}table_S5.tex" in 1/`i', replace noquote
drop table
macro drop star*

*------------------------------------------------------------------------------*

clear

exit
